#ifndef _CANARY2_UTIL_FILL_ZERO_H_
#define _CANARY2_UTIL_FILL_ZERO_H_

#include <type_traits>
#include <cstring> // ::memset
#include <cstddef>
#include <ranges>
#include <iterator>

namespace wilson::util
{
    template<typename T>
    void fill_zero(T* p, size_t n)
    {
        if constexpr (::std::is_fundamental_v<T>)
            ::memset(p, 0, n);
        else 
        {
            for (size_t i = 0; i < n; ++i)
                p[i] = T{};
        }
    }

    void fill_zero(::std::ranges::range auto& r)
    {
        for (auto& item : r)
        {
            // assign default value to each item
            item = typename ::std::iter_value_t<
                ::std::ranges::iterator_t<decltype(r)>
            >{};
        }
    }
}

#endif
